package cn.com.taurus.biz;

import cn.com.taurus.entity.Admins;
import cn.com.taurus.impl.AdminsImpl;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * @author zhy
 * @createTime 2021-6-23 16:40:24
 * @remark 后台人员Biz层
 * @version 1.0
 */
@Service
public class AdminsBiz{
    @Autowired
    AdminsImpl adminsImpl;
    public Admins selectAdmisByAAccount(String aAccount) { return adminsImpl.selectAdmisByAAccount(aAccount); }
    public int adminsUpdate(Admins admins){
        return adminsImpl.adminsUpdate(admins);
    }
    public Integer updateAImgUrl(@Param("aImgUrl") String aImgUrl, @Param("aAccount") String aAccount) {
        return adminsImpl.updateAImgUrl(aImgUrl,aAccount);
    }
    public int amendAdmins(Admins admins){
        return adminsImpl.amendAdmins(admins);
    }
    public List<Admins> selectAdmins(){
        return adminsImpl.selectAdmins();
    }
    public List<Admins> selectConditionAdmins(Admins admins){
        return adminsImpl.selectConditionAdmins(admins);
    }
    public Integer addAdmins(Admins admins){
        return adminsImpl.addAdmins(admins);
    }
    public Integer deleteByAId(Integer aId){
        return adminsImpl.deleteByAId(aId);
    }

    public void importAdmins(String url) {
        int i;
        Sheet sheet;
        Workbook book;
        Cell cell1,cell2,cell3,cell4,cell5,cell6,cell7,cell8;
        Cell[] cells;
        try {
            //t.xls为要读取的excel文件名
            System.out.println(url);
            book= Workbook.getWorkbook(new File(url));

            //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
            sheet=book.getSheet(0);
            //获取左上角的单元格
            cell1=sheet.getCell(0,0);
            cells = sheet.getRow(0); //获取第0行的一整行
            System.out.println();
            for (int j = 0; j < cells.length; j++) {
                System.out.print(cells[j].getContents()+",");
            }
            System.out.println();
            /* System.out.println("标题："+cell1.getContents()); */

            i=1;
            while(true){
                //获取每一行的单元格
                cell1=sheet.getCell(0,i);//（列，行）
                cell2=sheet.getCell(1,i);
                cell3=sheet.getCell(2,i);//最多查3列
                cell4=sheet.getCell(3,i);//这开始都是我加的
                cell5=sheet.getCell(4,i);
                cell6=sheet.getCell(5,i);
                cell7=sheet.getCell(6,i);
                cell8=sheet.getCell(7,i);
                if("".equals(cell1.getContents())==true)  //如果读取的数据为空
                    break;

                Admins admins = new Admins(0,cell1.getContents(),cell2.getContents(),"",cell4.getContents(),cell5.getContents(),cell6.getContents(),
                        cell7.getContents(),cell8.getContents());

                System.err.println(admins.toString());
                //新增数据
                Integer integer = adminsImpl.addAdmins(admins);


                i++;
            }
            book.close();
        } catch(Exception e) {
        }
    }
}
